package com.multi.thread.chapter01;

/**
 * 在java线程中有两种线程，一种是用户线程，另一种是守护线程
 *
 */
public class DaemonThread extends Thread {
	private int i = 0;
	
	@Override
	public void run() {
		try {
			while (true) {
				i++;
				System.out.println("i = " + (i));
				Thread.sleep(1000);
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		try {
			DaemonThread thread = new DaemonThread();
			thread.setDaemon(true);
			thread.start();
			Thread.sleep(6000);
			System.out.println("我离开thread对象也不在打印了，也就是停止了!");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
